﻿using Game1942.Library.Background;

namespace Game1942.Library.FlightPlans
{
    class HomingStrategy : FlightPlan
    {
        private const int verticalIncrement = 1;
        private Point targetPosition;

        // Establishes the position of the target and defines the increase in Y-axis
        public HomingStrategy(int speed,Point target): base(speed)
        {
            targetPosition = target;
        }

        // Get the next point on the trajectory of the flight plan
        public override Point GetNext()
        {
            var xDisplacement = actualPosition.X;
            var yDisplacement = actualPosition.Y + verticalIncrement;
            if (actualPosition.X > targetPosition.X) xDisplacement = actualPosition.X - 1;
            else 
                if (actualPosition.X < targetPosition.X) xDisplacement = actualPosition.X + 1;
            actualPosition = new Point(xDisplacement,yDisplacement);
            return actualPosition;
        }
    }
}
